import time
from selenium.webdriver.common.by import By
from common.Utils import BlogDriver

class BlogDetail:
    driver=""
    url=""
    def __init__(self):
        self.driver=BlogDriver.driver
        #设置 隐式等待
        self.driver.implicitly_wait(5)
        self.url="http://8.137.19.140:9090/blog_detail.html?blogId=43914"
        self.driver.get(self.url)

    # 测试 [登录状态] 用例
    def DetailTestSelf(self):
        #访问当前用户的博客详情页
        #检查博客标题是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.title")
        #检查博客内容框是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#detail")
        #检查博客发布时间是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.date")
        time.sleep(2)
        #检查用户昵称是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")
        #屏幕截图
        BlogDriver.getScreenShot()


    def DetailTestOther(self):
        #访问其他用户的博客详情页
        self.driver.get("http://8.137.19.140:9090/blog_detail.html?blogId=43919")
        time.sleep(2)
        #检查是否为其他用户的博客
        text=self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3").text
        print(text)
        assert text=="zhangsan"
        # 检查博客标题是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.title")
        #检查博客内容框是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#detail")
        #检查博客发布时间是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.date")
        # 检查用户昵称是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > h3")
        #检查博客详情页 ”编辑“  删除“ 按钮是否不存在  找不到编辑按钮 -- 抛异常
        edit=self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div > div.operating > button:nth-child(1)")
        # 屏幕截图
        BlogDriver.getScreenShot()

    #测试 [未登录状态] 用例
    def DetailsTestUnLogin(self):
            username = self.driver.find_element(By.CSS_SELECTOR, "#username").text
            passwd = self.driver.find_element(By.CSS_SELECTOR, "#password").text
            assert username == "" and passwd == ""
            # 屏幕截图
            BlogDriver.getScreenShot()












